﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EzyGoEzySystem.Models;

namespace EzyGoEzySystem.Services.DataStructures
{
    public class Node
    {
        public string BusStopName { get; set; }
        public double H { get; set; }
        public int NumOfConnection { get; set; }
        public List<Connection> Connection { get; set; }
        
        public Node(string name, double h, EzyGoEzyDBContext dbContext)
        {
            BusStopName = name;
            H = h;
            buildConnection(dbContext);
        }

        public void buildConnection(EzyGoEzyDBContext dbContext)
        {
            Connection = new List<Connection>();
            NumOfConnection = countConnections(BusStopName, dbContext); 

            //let graph build the connection
        }

        //method to count how many connections of Bus Stops
        public static int countConnections(string busStopName, EzyGoEzyDBContext dbContext)
        {
            int number = 0;
            var entry = from busStopEntry in dbContext.BusStop
                        where busStopEntry.Name == busStopName
                        select busStopEntry;
            var firstEntry = entry.First();
            int busStopID = firstEntry.ID;

            var entry1 = from routeEntry in dbContext.Route
                         where routeEntry.StartBusStopID == busStopID
                         select routeEntry;
            number = entry1.Count();
            return number;

        }
    }
}